package com.pcjavanet.domain;

 

import org.apache.log4j.Logger;

import com.pcjavanet.util.CommonUtil;

public class UChart extends BaseChart {
	protected static Logger logger = Logger.getLogger( UChart.class);
	private double uBar ;
	private double ucl ; 
	private double lcl ; 
	//average sample size ,each sub group size
	private double groupAverageSize ; 
	public double getGroupAverageSize() {
		return groupAverageSize;
	}

	public void setGroupAverageSize(double groupAverageSize) {
		this.groupAverageSize = groupAverageSize;
	}

	public double getUcl() {
		if ( groupAverageSize != 0 )
			this.ucl = this.uBar +  3 * Math.sqrt( uBar/groupAverageSize );
		else 
			logger.error(" groupAverageSize is zero ,so can't calculate ucl");
		return ucl ; 
	}

	public void setUcl(double ucl) {
		this.ucl = ucl;
	}

	public double getLcl() {
		if ( groupAverageSize != 0 )
			this.lcl = this.uBar -  3 * Math.sqrt( uBar /groupAverageSize);
		else  
			logger.error(" groupAverageSize is zero ,so can't calculate lcl");
		return lcl;
	}

	public void setLcl(double lcl) {
		this.lcl = lcl;
	}

	public double getuBar() {
		return uBar;
	}

	public void setuBar(double uBar) {
		this.uBar = uBar;
	}

 
	public void calculateGroupAverageSize( int totalDefects, int totalInspects  ) {
		if ( totalInspects == 0 ) {
			
		} else
			this.uBar =  (double) totalDefects  / totalInspects ;
	}
	
	public void calculateUBar (int totalDefects , int totalSubGroups ) {
		if ( totalSubGroups !=0 )
			groupAverageSize = CommonUtil.getPrecision( ((double) totalDefects )/ totalSubGroups ) ; 
	}
	
}
